package com.acwing.partition9;

import java.io.*;

/**
 * @author `RKC`
 * @date 2021/12/6 9:37
 */
public class AC886求组合数II {

    private static final int MOD = (int) (1e9 + 7);
    private static final int N = 100010;

    private static long quickPow(long a, int k, int p) {
        long res = 1;
        while (k != 0) {
            if ((k & 1) == 1) res = res * a % p;
            k >>= 1;
            a = a * a % p;
        }
        return res;
    }

    private static void init(long[] fact, long[] infact) {
        fact[0] = infact[0] = 1;
        for (int i = 1; i < N; i++) {
            fact[i] = fact[i - 1] * i % MOD;
            //计算阶乘的逆元，快速幂求逆元
            infact[i] = (infact[i - 1] * quickPow(i, MOD - 2, MOD)) % MOD;
        }
    }

    public static void main(String[] args) throws IOException {
        long[] fact = new long[N], infact = new long[N];
        init(fact, infact);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] s = reader.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        while (n-- > 0) {
            s = reader.readLine().split(" ");
            int a = Integer.parseInt(s[0]), b = Integer.parseInt(s[1]);
            long answer = (((fact[a] * infact[b]) % MOD * infact[a - b])) % MOD;
            writer.write(answer + "\n");
        }
        writer.flush();
    }
}
